﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using _1906Ultras.Model;

namespace _1906Ultras.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class EventViewModel : ViewModelBase
    {


        public string ApplicationTitle
        {
            get { return "1906 Ultras"; }
        }



        /// <summary>
        /// Initializes a new instance of the EventViewModel class.
        /// </summary>
        public EventViewModel()
        {
            Messenger.Default.Register<PropertyChangedMessage<Event>>(this,
                                                                         (action) => UpdateEvent(action.NewValue));
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}
        }



        private void UpdateEvent(Event newEvent)
        {
            CurrentEvent = newEvent;
        }


        /// <summary>
        /// The <see cref="CurrentEvent" /> property's name.
        /// </summary>
        public const string CurrentEventPropertyName = "CurrentEvent";

        private Event _currentEvent;

        /// <summary>
        /// Gets the CurrentEvent property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public Event CurrentEvent
        {
            get
            {
                return _currentEvent;
            }

            set
            {
                if (_currentEvent == value)
                {
                    return;
                }

                var oldValue = _currentEvent;
                _currentEvent = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(CurrentEventPropertyName);
            }
        }
    }
}